package com.naihe.anderson.sms.util;

import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;

public class MyAnimations{
	
	private static float xOffset = -1;
	
	static TranslateAnimation RightToLeftScaleAnimation;
	static TranslateAnimation LeftToRightScaleAnimation;
	
	public static void initOffset(Context context){
		if(xOffset == -1){
			xOffset	= PxDipChangeUtil.dipToPx(120, context);
			RightToLeftScaleAnimation = new TranslateAnimation(xOffset, 0.0f, 0.0f, 0.0f);
			LeftToRightScaleAnimation = new TranslateAnimation(0.0f, xOffset, 0.0f, 0.0f);
		}
//		xOffset	= (int) (5.667 * context.getResources().getDisplayMetrics().density);//8
	}
	
	public static Animation getRotateAnimation(float fromDegrees ,float toDegrees,int durationMillis){
		RotateAnimation rotate = new RotateAnimation(fromDegrees, toDegrees,
				Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
		rotate.setDuration(durationMillis);
		rotate.setFillAfter(true);
		return rotate;
	}

	public static void startAnimationsIn(LinearLayout viewgroup, LinearLayout buttonsLayout,int durationMillis) {
		RightToLeftScaleAnimation.setDuration(durationMillis);
		buttonsLayout.setVisibility(View.VISIBLE);
		viewgroup.startAnimation(RightToLeftScaleAnimation);
	}
	
	public static void startAnimationsOut(LinearLayout viewgroup, final LinearLayout buttonsLayout,int durationMillis) {
		LeftToRightScaleAnimation.setDuration(durationMillis);
		LeftToRightScaleAnimation.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {
				
			}
			
			@Override
			public void onAnimationRepeat(Animation animation) {
				
			}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				buttonsLayout.setVisibility(View.GONE);
			}
		});
		viewgroup.startAnimation(LeftToRightScaleAnimation);
	}

	
}